<template>
  <div class="charts" ref="charts"></div>
</template>

<script>
// 引入echarts
import echarts from 'echarts';
export default {
  name:'',
  props:['lineInfo'],
  data() {
    return {
      lineData:[
        ['最低分',0],
        ['平均分',0],
        ['最高分',0],
      ],
      option:{
        tooltip: {
          formatter: function (params) {
              var data = params.data;
              return data[0]+','+data[1].toFixed(1);
            }
        },
        xAxis: {
          type: 'category',
          show:false,
        },
        yAxis: {
          show:false,
        },
        //系列
        series: [
          {
            type: "line",
            data: this.lineData,
            //拐点的样式的设置
            itemStyle: {
              opacity: 1,
            },
            //线条的样式
            lineStyle: {
              color: "purple",
            },
            //填充颜色设置
            areaStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "purple", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "#fff", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
          },
        ],
        //布局调试
        grid: {
          left: 0,
          top: 5,
          right: 0,
          bottom: 5,
        },
      },
    }
  },
  methods: {
    refreshData(){
      this.lineData[0][1] = this.lineInfo.minScore;
      this.lineData[1][1] = this.lineInfo.avgScore;
      this.lineData[2][1] = this.lineInfo.maxScore;
      let lineCharts = echarts.init(this.$refs.charts);
      // 配置数据
      this.option.series[0].data = this.lineData;
      lineCharts.setOption(this.option);
    }
  },
  watch:{
    'lineInfo.avgScore':{
      handler(){
        this.refreshData();
      }
    },
  }
}
</script>

<style scoped>
.charts{
  width:100%;
  height:100%;
}
</style>